namespace IECAS.ERS.Services.Pop3
{

  /// <summary>
  /// The result of a Pop3 request with a boolean status and a text message
  /// </summary>
  public class Pop3OperationResult {

    private string message;
    private bool isSuccessful;

    /// <summary>
    /// Returns the message from the operation
    /// </summary>
    public string Message {
      get { return message; }
    }

    /// <summary>
    /// True if the operation was successful.
    /// </summary>
    public bool IsSuccessful {
      get { return isSuccessful; }
    }

    /// <summary>
    /// Creates a new operation result instance.
    /// </summary>
    /// <param name="isSuccessful">Was this operation successful?</param>
    /// <param name="message">The message attached to the result</param>
    public Pop3OperationResult(bool isSuccessful, string message) {

      this.isSuccessful = isSuccessful;
      this.message = message;
    }

    /// <summary>
    /// Returns a string representation for this operation result.
    /// </summary>
    /// <returns>The string representation closely approximates the POP
    /// server's actual result.</returns>
    public override string ToString() {
      
      return (IsSuccessful ? "+OK " : "-ERR ") + Message;
    }
  }

  /// <summary>
  /// The result of a Pop3 request with a boolean status, a text message and 
  /// a multiline content part.
  /// </summary>
  public class Pop3MultilineOperationResult : Pop3OperationResult {

    private string[] content;

    /// <summary>
    /// Returns the multiline content from the operation
    /// </summary>
    /// <returns>The content, or null if none exists.</returns>
    public string[] GetContent() {

      if (content == null)
        return null;

      return (string[])content.Clone();
    }

    /// <summary>
    /// Creates a new operation result instance.
    /// </summary>
    /// <param name="isSuccessful">Was this operation successful?</param>
    /// <param name="message">The message attached to the result</param>
    /// <param name="content">The multiline content part of the operation</param>
    public Pop3MultilineOperationResult(bool isSuccessful, string message, string[] content) 
      : base(isSuccessful, message) {

      this.content = content;
    }
  }

  /// <summary>
  /// The result of a Pop3 STAT request.
  /// </summary>
  public class Pop3StatOperationResult : Pop3OperationResult {

    private int messageCount;
    private int totalBytes;

    /// <summary>
    /// Number of messages in the mailbox
    /// </summary>
    public int MessageCount {
      get { return messageCount; }
    }

    /// <summary>
    /// The total bytes in the mailbox
    /// </summary>
    public int TotalBytes {
      get { return totalBytes; }
    }

    /// <summary>
    /// Creates a new operation result instance.
    /// </summary>
    /// <param name="isSuccessful">Was this operation successful?</param>
    /// <param name="message">The message attached to the result</param>
    /// <param name="msgs">Number of messages in the mailbox</param>
    /// <param name="bytes">The mailbox total size in bytes</param>
    public Pop3StatOperationResult(bool isSuccessful, string message, int msgs, int bytes) 
      : base(isSuccessful, message) {

      this.messageCount = msgs;
      this.totalBytes = bytes;
    }
  }

}